package com.hangim.pce.enums;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.google.common.collect.Lists;

import java.util.List;

/**
 * 规则等级
 */
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum RuleLevel {
    DISABLE("DISABLE", 1, "禁用"),
    USABLE("USABLE", 2, "可用"),
    CAREFUL("CAREFUL", 3, "慎用"),
    INAPPROPRIATE("INAPPROPRIATE", 4, "不宜"),
    HIGH("HIGH", 5, "高"),
    MID("MID", 6, "中"),
    LOW("LOW", 7, "低"),
    OTHER("OTHER", 0, "其他");

    private final String code;

    private final Integer num;

    private final String desc;

    RuleLevel(final String code, final Integer num, final String desc) {
        this.code = code;
        this.desc = desc;
        this.num = num;
    }

    /**
     * 把所有枚举定义转换成实体
     *
     * @return List<RuleLevel>
     */
    public static List<RuleLevel> getList() {
        List<RuleLevel> list = Lists.newArrayList();

        RuleLevel[] ts = RuleLevel.values();
        for (RuleLevel type : ts) {
            list.add(type);
        }
        return list;
    }

    public static RuleLevel getRuleLevel(String code) {
        RuleLevel[] ts = RuleLevel.values();
        for (RuleLevel t : ts) {
            if (t.getCode().equalsIgnoreCase(code)) {
                return t;
            }
        }
        return OTHER;
    }

    public static RuleLevel getRuleLevelByDesc(String desc) {
        RuleLevel[] ts = RuleLevel.values();
        for (RuleLevel t : ts) {
            if (t.getDesc().contains(desc)) {
                return t;
            }
        }
        return OTHER;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public Integer getNum() {
        return num;
    }
}
